const { defineConfig } = require("@vue/cli-service");
const path = require("path");

//通过全局对象process.env来获取  环境
console.log(process.env);

function resolve(dir) {
  return path.resolve(dir);
}
module.exports = defineConfig({
  //构建项目一定要加这个属性，不然资源会挂掉（产品环境）
  publicPath: ".",
  transpileDependencies: true,
  lintOnSave: false,
  //开发服务器的配置 ,配置完一定要重启项目
  devServer: {
    //配置启动服务器的端口号
    port: parseInt(process.env.VUE_APP_PORT),
    //匹配地址
    proxy: {
      "/api": {
        //目标服务器
        // target:'http://chst.vip',
        target: process.env.VUE_APP_BASE_URL,
        //路径重写
        pathRewrite: {
          "^/api": "",
        },
      },
    },
  },
  chainWebpack: (config) => {
    //别名配置
    config.resolve.alias
      .set("&", resolve("src"))
      .set("assets", resolve("src/assets"))
      .set("components", resolve("src/components"))
      .set("layout", resolve("src/layout"))
      .set("base", resolve("src/base"))
      .set("static", resolve("src/static"));

      //打包配置hash文件名 一般是使用版本号+时间戳
      config.output
        .filename(
          `assets/js/[name].${process.env.ENV_APP_VERSION}.${+new Date()}.js`

        )
        .chunkFilename(
          `assets/js/[name].${process.env.ENV_APP_VERSION}.${+new Date()}.js`
        )
  },
});
